package io.github.veigara.tcp.framework.factory;

/**
 * @author : zhouhx
 * @date : 2025/6/6 13:29
 */

import io.github.veigara.tcp.framework.model.DeviceType;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 设备组件工厂注册表
 */
public class DeviceComponentFactoryRegistry {
    private final Map<DeviceType, DeviceComponentFactory> factories = new ConcurrentHashMap<>();

    public void registerFactory(DeviceComponentFactory factory) {
        factories.put(factory.getDeviceType(), factory);
    }

    public DeviceComponentFactory getFactory(DeviceType deviceType) {
        return factories.getOrDefault(deviceType, new DefaultDeviceComponentFactory(deviceType));
    }
}
